﻿using System.Web;
using Super.Common;
using Super.DomainService;
using Super.Entities;

public partial class Link
{
    private static FileMethod _file = new FileMethod(BangKeService.Domain.File.Url);
    private static _AssetLinkInfo _asset = new _AssetLinkInfo();

    public static FileMethod File
    {
        get { return _file; }
    }

    public static _AssetLinkInfo Asset
    {
        get { return _asset; }
    }

    /// <summary> 
    /// 信用标志图标地址
    /// </summary>
    /// <returns></returns>
    public static string UserCreditUrl()
    {
        return File + "/System/UserCredit/";
    }

    /// <summary>
    /// 头衔图标地址
    /// </summary>
    /// <returns></returns>
    public static string UserTitleUrl()
    {
        return File + "/System/UserTitle/";
    }

    /// <summary>
    /// 用户组图标地址
    /// </summary>
    /// <returns></returns> 
    public static string UserGroupUrl()
    {
        return File + "/System/UserGroup/";
    }

    /// <summary>
    /// 银行图标地址
    /// </summary>
    /// <returns></returns>
    public static string BankUrl()
    {
        return File + "/System/Bank/";
    }

    /// <summary>
    /// 支付工具图标地址
    /// </summary>
    /// <returns></returns>
    public static string PayToolUrl()
    {
        return File + "/System/PayTool/";
    }

    #region Nested type: FileMethod

    public class FileMethod : BaseLinkInfo
    {
        public FileMethod(string p)
            : base(p)
        { }

        /// <summary>
        /// 获取文件绝对路径
        /// </summary>
        /// <param name="resId">文件ID</param>
        /// <returns>返回文件的路径。</returns>
        /// <remarks>@bangq 2011 10 20</remarks>
        public string ImagePath(int resId)
        {
            string fileDomain = BangKeService.Domain.File.Url;

            //BK_Resources resModel = ResourcesService.Get(resId);

            string resUrl = "";

            //if (resModel != null)
            //{
            //    resUrl = fileDomain + "/" + resModel.ResourcesUrl;
            //}

            return resUrl;
        }

        /// <summary>
        /// 获取文件的绝对地址
        /// 如果存了 fileInfo 的ResUrl,那么强烈建议使用次方法，可以减少一次数据库交互
        /// </summary>
        /// <param name="fileInfo"></param>
        /// <returns></returns>
        /// <remarks>bangq@201022 add</remarks>
        //public string ImagePath(BK_FileInfo fileInfo)
        //{
        //    string fileDomain = BangKeService.Domain.File.Url;
        //    string resUrl = "";

        //    if (fileInfo != null)
        //    {
        //        if (!string.IsNullOrEmpty(fileInfo.ResUrl))
        //        {
        //            resUrl = fileDomain + "/" + fileInfo.ResUrl;
        //        }
        //        else
        //        {
        //            resUrl = ImagePath(fileInfo.Id);
        //        }
        //    }

        //    return resUrl;
        //}

        /// <summary>
        /// 获取文件绝对路径
        /// </summary>
        /// <param name="resId">文件ID</param>
        /// <returns>返回文件的路径。</returns>
        public string DownPath(int resId)
        {
            string fileDomain = BangKeService.Domain.File.Url;

            string resUrl = fileDomain + "/file?f=" + resId;

            return resUrl;
        }

        /// <summary>
        /// 获取头像地址
        /// </summary>
        /// <param name="uid">用户UserId</param>
        /// <param name="avatarSign">用户是否上传了头像 1为有 0=没有 传入 BK_User.AvatarSign</param>
        /// <param name="avatarSize">头像的尺寸，AvatarSizeEnum 枚举类型</param>
        /// <returns></returns>
        public string GetAvatarUrl(int uid, short avatarSign,
                                   AvatarSizeEnum avatarSize)
        {
            if (avatarSign == 1) //如果用户上传了头像
            {
                string avatarUrl = BangKeService.Domain.File.Url + "/avatar/useravatar/" + uid + "/" + uid + "_avatar_" +
                                   avatarSize.ToString() +
                                   ".jpg";
                return avatarUrl;
            }
            else
            {
                return GetDefaultAvatarUrl(uid, avatarSize);
            }


        }

        /// <summary>
        /// 获取头像地址
        /// </summary>
        /// <param name="userModel">用户实体</param>
        /// <param name="avatarSize">头像的尺寸，AvatarSizeEnum 枚举类型</param>
        /// <returns></returns>
        //public string GetAvatarUrl(BK_User userModel, AvatarSizeEnum avatarSize)
        //{
        //    return GetAvatarUrl(userModel.UID, userModel.AvatarSign, avatarSize);
        //}

        /// <summary>
        /// 获取默认头像
        /// </summary>
        /// <param name="uid">用户的UID</param>
        /// <param name="avatarSize">头像的尺寸，AvatarSizeEnum 枚举类型</param>
        /// <returns></returns>
        public string GetDefaultAvatarUrl(int uid, AvatarSizeEnum avatarSize)
        {
            string size = "";
            switch (avatarSize)
            {
                case AvatarSizeEnum.Large:
                    size = "large";
                    break;
                case AvatarSizeEnum.Medium:
                    size = "medium";
                    break;
                case AvatarSizeEnum.Small:
                    size = "small";
                    break;
            }

            string avatarUrl = BangKeService.Domain.File.Url + "/avatar/default/" + "avatar_" + size + ".jpg";
            return avatarUrl;
        }

        /// <summary>
        /// 获取用户的链接，有店铺转到店铺，没有店铺转到用户信息页
        /// </summary>
        /// <param name="userModel"></param>
        /// <returns></returns>
        //public string UserUrl(BK_User userModel)
        //{
        //    string result;
        //    if (userModel.HasShop == 1)
        //    {
        //        result = BangKeService.Domain.Shop.Url + "/shop?uid=" + userModel.UID;
        //    }
        //    else
        //    {
        //        result = BangKeService.Domain.Main.Url + "/user?u=" + userModel.UID;
        //    }

        //    return result;
        //}
    }

    #endregion

    #region Nested type: _AssetLinkInfo

    public class _AssetLinkInfo : IHtmlString
    {
        private _BaseAssetProject _image = new _BaseAssetProject("image");
        private _BaseAssetProject _images = new _BaseAssetProject("images");

        private _BaseAssetProject _plus = new _BaseAssetProject("plus");
        private _ScriptAssetProject _script = new _ScriptAssetProject("script");
        private _BaseAssetProject _sytle = new _BaseAssetProject("style");

        public _BaseAssetProject Style
        {
            get { return _sytle; }
        }

        public _ScriptAssetProject Script
        {
            get { return _script; }
        }

        public _BaseAssetProject Image
        {
            get { return _image; }
        }

        public _BaseAssetProject Images
        {
            get { return _images; }
        }

        public _BaseAssetProject Plus
        {
            get { return _plus; }
        }

        #region Nested type: _BaseAssetProject

        public class _BaseAssetProject : BaseLinkInfo
        {
            public _BaseAssetProject(string path)
                : base("http://" + BangKeService.Domain.Assets.ToString() + "/" + path)
            {
                //Path 必须大写.
                Base = Path + "/base";
                Help = Path + "/help";
                Pay = Path + "/pay";
                Shop = Path + "/shop";
                Task = Path + "/task";
                Resource = Path + "/resource";
                UserCenter = Path + "/usercenter";
                Web = Path + "/web";
                Common = Path + "/common";
            }

            public string Base { get; private set; }

            public string Help { get; private set; }

            public string Pay { get; private set; }

            public string Resource { get; private set; }

            public string Shop { get; private set; }

            public string Task { get; private set; }

            public string UserCenter { get; private set; }

            public string Web { get; private set; }

            public string Common { get; private set; }
        }

        public class _ScriptAssetProject : _BaseAssetProject
        {
            public _ScriptAssetProject(string path)
                : base(path)
            {
                JQuery = Common + "/jquery.min.js";
                Validate = Common + "/validate.js";
                BkDialog = Common + "/bkdialog.js";
            }

            public string JQuery { get; private set; }

            public string Validate { get; private set; }

            public string BkDialog { get; private set; }
        }
        #endregion

        public string ToHtmlString()
        {
            return BangKeService.Domain.Assets.Url;
        }
    }

    #endregion

    #region Nested type: _HelpLinkInfoDomain

    public partial class _HelpLinkInfoDomain : BaseLinkInfo
    {
        #region Nested type: AskLinkInfoController

        public partial class AskLinkInfoController : BaseLinkInfo
        {
            #region Nested type: DetailsLinkInfoAction

            public partial class DetailsLinkInfoAction : BaseLinkInfo
            {
                public BaseLinkInfo this[int helpId]
                {
                    get { return new BaseLinkInfo(Path + "/" + URL.New("hid=" + helpId)); }
                }
            }

            #endregion

            #region Nested type: IndexLinkInfoAction

            public partial class IndexLinkInfoAction : BaseLinkInfo
            {
                public BaseLinkInfo this[int typeId = 0, int pageIndex = 0]
                {
                    get
                    {
                        return
                            new BaseLinkInfo(Path + "/" +
                                             URL.New("pageIndex=" + pageIndex + (typeId > 0 ? ",tid=" + typeId : "")));
                    }
                }
            }

            #endregion
        }

        #endregion

        #region Nested type: SysLinkInfoController

        public partial class SysLinkInfoController : BaseLinkInfo
        {
            #region Nested type: DetailLinkInfoAction

            public partial class DetailLinkInfoAction : BaseLinkInfo
            {
                public BaseLinkInfo this[int typeId = 0, int helpId = 0]
                {
                    get { return new BaseLinkInfo(Path + "/" + URL.New(typeId > 0 ? "t=" + typeId : "d=" + helpId)); }
                }
            }

            #endregion

            #region Nested type: IndexLinkInfoAction

            public partial class IndexLinkInfoAction
            {
                public BaseLinkInfo this[int typeId]
                {
                    get { return new BaseLinkInfo(Path + "/" + URL.NewFull("tid=" + typeId)); }
                }
            }

            #endregion
        }

        #endregion
    }

    #endregion

    #region Nested type: _MainLinkInfoDomain

    public partial class _MainLinkInfoDomain : BaseLinkInfo
    {
        #region Nested type: NoticeLinkInfoController

        public partial class NoticeLinkInfoController : BaseLinkInfo
        {
            public BaseLinkInfo this[int id]
            {
                get { return new BaseLinkInfo(Path + "/" + id); }
            }

            #region Nested type: IndexLinkInfoAction

            public partial class IndexLinkInfoAction : BaseLinkInfo
            {
            }

            #endregion
        }

        #endregion

        #region Nested type: UserLinkInfoController

        //public partial class UserLinkInfoController : BaseLinkInfo
        //{
        //    #region Nested type: IndexLinkInfoAction

        //    public partial class IndexLinkInfoAction : BaseLinkInfo
        //    {
        //        public BaseLinkInfo this[int userId]
        //        {
        //            get
        //            {
        //               // BK_User userModel = UserService.Get(userId);

        //              //  return new BaseLinkInfo(File.UserUrl(userModel));
        //            }
        //        }
        //    }

        //    #endregion
        //}

        #endregion
    }

    #endregion
}